include($ENV{IDF_PATH}/tools/cmake/project.cmake)

if("${DEVICE}" STREQUAL "")
	if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.dev.cmake")
		include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.dev.cmake")
	else()
		if("${IDF_TARGET}" STREQUAL "esp32")
			set("DEVICE" "dev-wrov1") #"dev-esp32")
		endif()
		if("${IDF_TARGET}" STREQUAL "esp32s3")
			set("DEVICE" "dev-esp32s3")
		endif()
		if("${IDF_TARGET}" STREQUAL "esp32p4")
			set("DEVICE" "dev-esp32p4-wifi")
		endif()
		
	endif()
endif()

if("${DEVICE}" STREQUAL "dev-esp32")
	set(DEVICE_SDKCONFIG "sdkconfig.defaults.esp32")
elseif("${DEVICE}" STREQUAL "dev-esp32s3")
	set(DEVICE_SDKCONFIG "sdkconfig.defaults.esp32s3")
elseif("${DEVICE}" STREQUAL "prod-esp32N8R2")
	set(DEVICE_SDKCONFIG "sdkconfig.defaults.prod8R2")
elseif("${DEVICE}" STREQUAL "dev-wrov1")
	set(DEVICE_SDKCONFIG "sdkconfig.defaults.devwrov1")
elseif("${DEVICE}" STREQUAL "prod-xiao")
	set(DEVICE_SDKCONFIG "sdkconfig.defaults.prodxiao")
elseif("${DEVICE}" STREQUAL "dev-esp32p4-eth")
	set(DEVICE_SDKCONFIG "sdkconfig.defaults.p4eth")
elseif("${DEVICE}" STREQUAL "dev-esp32p4-wifi")
	set(DEVICE_SDKCONFIG "sdkconfig.defaults.p4wifi")
else()
	message("FATAL_ERROR" "The \"${DEVICE}\" not supported!!!")
endif()

set(SDKCONFIG_DEFAULTS "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults")

set(SDKCONFIG_DEFAULTS "${SDKCONFIG_DEFAULTS};${CMAKE_CURRENT_LIST_DIR}/cfg/${DEVICE_SDKCONFIG}")

if(CMAKE_BUILD_TYPE)
	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
		set(SDKCONFIG_DEFAULTS "${SDKCONFIG_DEFAULTS};${CMAKE_CURRENT_LIST_DIR}/sdkconfig.release")
	endif()
endif()

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cfg/${DEVICE_SDKCONFIG}")
	set(SDKCONFIG_DEFAULTS "${SDKCONFIG_DEFAULTS};${CMAKE_CURRENT_SOURCE_DIR}/cfg/${DEVICE_SDKCONFIG}")
endif()